package com.sun.designpatternsdemo.strategy.bean

import android.util.Log

/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：2021/6/29 15:15
 * 描述：游戏角色的超类
 *
 */
abstract class Role {
    protected var name: String? = null

    private var display: IDisplayBehavior? = null
    private var defend: IDefendBehavior? = null
    private var run: IRunBehavior? = null
    private var attack: IAttackBehavior? = null
    fun setDisplay(display: IDisplayBehavior): Role {
        this.display = display
        return this
    }

    fun setDefend(defend: IDefendBehavior): Role {
        this.defend = defend
        return this
    }

    fun setRun(run: IRunBehavior): Role {
        this.run = run
        return this
    }

    fun setAttack(attack: IAttackBehavior): Role {
        this.attack = attack
        return this
    }


    //着装
    fun display() {
        display?.display()
    }

    //逃跑
    fun run() {
        run?.run()
    }

    //攻击
    fun attack() {
        attack?.attack()
    }

    //防御
    fun defend() {
        defend?.defend()
    }
}

interface IAttackBehavior {
    fun attack()
}

interface IDefendBehavior {
    fun defend()
}

interface IDisplayBehavior {
    fun display()
}

interface IRunBehavior {
    fun run()
}

class RoleA(name: String?) : Role() {
    init {
        this.name = name
    }
}
class RunJCTQ:IRunBehavior{
    override fun run() {
        Log.e("---", "金蝉脱壳")
    }
}
class AttackXL :IAttackBehavior{
    override fun attack() {
        Log.e("---", "降龙十八掌")
    }
}

class DefendTMS:IDefendBehavior{
    override fun defend() {
        Log.e("---", "铁布衫")
    }

}
class DisplayYZ: IDisplayBehavior{
    override fun display() {
        Log.e("---", "样子2")
    }

}